﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Galaktika.BI.Charting
{
    public delegate void ModifiedChangedEventHandler(object sender, ModifiedChangedEventArgs e);

    public class ModifiedChangedEventArgs : EventArgs
    {
        private object addedItem;

        public ModifiedChangedEventArgs(object addedItem)
        {
            this.addedItem = addedItem;
        }

        public object AddedItem
        {
            get { return addedItem; }
        }
    }
    public class CustomList<T> : List<T>, IModifiable
    {
        public CustomList()
            : base()
        {
        }

        public CustomList(IEnumerable<T> collection)
            : base(collection)
        {
        }

        new public void Add(T item)
        {
            base.Add(item);
            var args = new ModifiedChangedEventArgs(item);
            RaiseCollectionModified(args);
        }

        #region IModifiable Members

        public event ModifiedChangedEventHandler CollectionModified;

        public void RaiseCollectionModified(ModifiedChangedEventArgs e)
        {
            // вызов делегата через посредника EventHandler нужно для
            // безопасности в многопотоковом режиме
            ModifiedChangedEventHandler handler = CollectionModified;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion IModifiable Members
    }
}
